package com.github.redis.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gcq
 * @Create 2022-06-15
 */
@RestController
@Slf4j
public class PageViewController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/view/{id}")
    public String view(@PathVariable String id) {
        String key = "article:" + id;
        Long increment = stringRedisTemplate.opsForValue().increment(key);
        log.info("key={},阅读量为{}",key, increment);
        return "成功";
    }
}